import CryptoJS from './node_modules/crypto-js/crypto-js.js'
import MD5 from './pages/index/md5.js'
import {AES_Decryptecb} from './pages/index/ECB.js'

export const mixin = {
	data() {
		return {
			headers:{
				'Cache-Control':'no-cache',
				'Accept':'*/*',
				'Accept-Encoding':'gzip, deflate, br',
				'Connection':'keep-alive',
				'Content-Type':'application/x-www-form-urlencoded',
				'Content-Length':'154'
			}
		};
	},
	methods:{
		//DES的CBC加密
		getDes(message) {
			var key = 'ccufesyn';
			var iv = 'ccufesyn';
			var crypto_key = CryptoJS.enc.Utf8.parse(key);
			var crypto_iv = CryptoJS.enc.Utf8.parse(iv.substr(0,8));
		
			var encode_str = CryptoJS.TripleDES.encrypt(message, crypto_key, {
				iv:crypto_iv,    
				mode:CryptoJS.mode.CBC,    
				padding:CryptoJS.pad.Pkcs7});
			return encode_str.ciphertext.toString().toUpperCase();
		},
		//获取文本的MD5值
		getMd5(text){
			return MD5(text)
		},
		//将对象拼接成字符串
		getObjToStr(params){
			return decodeURIComponent(Object.keys(params).map(i => `${i}=${encodeURIComponent(params[i]||'')}`).join('&')+'ccufesyn')
		},
		// 获取设备名
		getDev(){
			let e = uni.getSystemInfoSync().deviceModel
			uni.setStorageSync('dev',e.replace(/\s*/g,""))
		},
		getAES_Decryptecb(word){
			return AES_Decryptecb(word)
		}
	}
}